package com.harry.demo7;

import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author Harry
 * @date 2018/3/21 17:19
 */

@Mapper
public interface UserMapper {

	@Select("SELECT * FROM USER WHERE NAME = #{name}")
	User findByName(@Param("name") String name);

	@Insert("INSERT INTO USER(NAME, AGE) VALUES(#{name}, #{age})")
	int insert(@Param("name") String name, @Param("age") Integer age);

	@Insert("INSERT INTO USER(NAME, AGE) VALUES(#{name,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER})")
	int insertByMap(Map<String, Object> map);

	@Insert("INSERT INTO USER(NAME, AGE) VALUES(#{username}, #{age})")
	int insertByUser(User user);

	@Update("UPDATE user SET age=#{age} WHERE name=#{username}")
	void update(User user);

	@Delete("DELETE FROM user WHERE id =#{id}")
	void delete(Long id);

	@Results({ @Result(property = "username", column = "name"), @Result(property = "age", column = "age") })
	@Select("SELECT name, age FROM user")
	List<User> findAll();
}
